package com.kai.controller;

import com.kai.pojo.UserCourse;
import com.kai.service.UserCourseService;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserCourseController {
    @Autowired
    private UserCourseService userCourseService;

    /*添加课程*/
    @GetMapping("/userAddCourse")
    public Map<String,String> userAddCourse(@RequestParam("user_id") String user_id, @RequestParam("course_id") String course_id){
        int i = userCourseService.selectUserAddCourse(user_id, course_id);
        HashMap<String, String> map = new HashMap<>();
        if (i>0){
            map.put("msg","你已经添加过该课程");
            return map;
        }else{
            userCourseService.userAddCourse(user_id,course_id);
            map.put("msg","添加成功");
            return map;
        }
    }
    /*查询用户参加的全部课程*/
    @GetMapping("/selectUserAddAllCourse/{user_id}")
    public List<UserCourse> selectUserAddAllCourse(@PathVariable("user_id") String user_id){
        return userCourseService.selectUserAddAllCourse(user_id);
    }

    /*用户删除已经添加的课程*/
    @PostMapping("/deleteUserAddAllCourse/{id}")
    public Map<String,String> deleteUserAddAllCourse(@PathVariable("id") String id){
        HashMap<String, String> map = new HashMap<>();
        int i = userCourseService.deleteUserAddAllCourse(id);
        if (i>0){
            map.put("msg","删除课程成功");
            return map;
        }else{
            map.put("msg","删除课程失败");
            return map;
        }
    }
}
